home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / MKTEMPNM.C < prev    next >
C/C++ Source or Header  |  1991-12-07  |  2KB  |  58 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    m k t e m p n m . c                                             */
  3. /*                                                                    */
  4. /*    Host Support routines for UUPC/extended                         */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of hlib.c                         ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. #include <io.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <limits.h>
  17. #include <time.h>
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*                    UUPC/extended include files                     */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. #include "lib.h"
  24. #include "hlib.h"
  25.  
  26. /*--------------------------------------------------------------------*/
  27. /*                          Global variables                          */
  28. /*--------------------------------------------------------------------*/
  29.  
  30. currentfile();
  31.  
  32. /*--------------------------------------------------------------------*/
  33. /*    m k t e m p n a m e                                             */
  34. /*                                                                    */
  35. /*    Generate a temporary name with a pre-defined extension          */
  36. /*--------------------------------------------------------------------*/
  37.  
  38. char *mktempname( char *buf, char *extension)
  39. {
  40.    static size_t file = 0;
  41.    if (buf == NULL)           /* Do we need to allocate buffer?         */
  42.    {
  43.       buf = malloc( FILENAME_MAX );
  44.       checkref(buf);
  45.    } /* if */
  46.  
  47.    for (file++ ; file < INT_MAX ; file++ )
  48.    {
  49.       sprintf(buf,"%s/uupc%04.4x.%s", tempdir, file, extension);
  50.       if ( access( buf, 0 ))  /* Does the host file exist?           */
  51.          break;               /* No  --> Use the name                */
  52.    } /* for */
  53.  
  54.    printmsg(5,"Generated temporary name: %s",buf);
  55.    return buf;
  56.  
  57. } /* mktempname */
  58.